<template>
	<div>
		<div style="padding-top: 0.9rem;"></div>
		<div :class="header_class">
			<i class="iconfont icon-zuo" style="flex: 0.2" @click="Back" v-if="show_leftIcon"></i>
			<!--<i v-else style="flex: 0.2"></i>-->
			<div class="title">{{title}}</div>
			<div v-if="show_saveBtn" class="save">保存</div>
			<div v-if="show_searchBtn" class="search">搜索</div>
			<div v-if="show_rightBlank" class="search"></div>
		</div>
	</div>
</template>

<script>
	export default {
		name: "user_Header",
		data() {
			return {
				backhome:"",
			}
		},
		props: {
			title: String,
			showSearch: Boolean,
			/* headerClass:String,*/
			moduleName: String,
		},
		computed: {
			/*模块名称 主页面main  修改个人资料mine  用户登陆user  */
			show_saveBtn() {
				if (this.moduleName != "mine") return false
				return this.showSearch ? false : true
			},
			show_searchBtn() {
				if (this.moduleName != "mine") return false
				return this.showSearch ? true : false
			},
			show_leftIcon() {
				if (this.moduleName != "main") return true
				return false
			},
			show_rightBlank() {
				console.log(this.moduleName,6541563); 
				if (this.moduleName == "match" || this.moduleName == "user" || this.moduleName == "matchs" || this.moduleName ==
					"endMatch" || this.moduleName == "matchStatistics"||this.moduleName == "match_going") return true
			},
			header_class() {
				let Class = 'header-defualt'
				if (this.moduleName == 'user') Class = 'header-transparent'
				return `header ${Class}`
			},
		},
		methods: {
			// 点击返回强制返回到赛事页,防止分享出去无法返回
			Back() {
				console.log(this.$router);  
				console.log(this.moduleName);  
				if(sessionStorage.getItem("isback")=='back'){
					sessionStorage.removeItem("isback")
					this.$router.push({
						path:'/match',
					})
				}
			else if (this.moduleName == 'matchStatistics') {
          // let url = location.href
					// this.$router.push({
					// 	path: '/match'
					// })
					this.$router.go(-1)
				}
				else if(this.moduleName == "endMatch"){
					this.$router.push({
						path:'/match',
					})
					return false
				}
				else if(this.moduleName == "match_going" || this.moduleName == "matchs"){
					this.$router.push({
						path:'/match',
					})
					return false
				}
					else {
					// let url = location.href
					// this.$router.go(-1)
           if (window.history.length <= 1) {
              this.$router.push({
                path:'/match',
              })
              return false
				} else {
					this.$router.go(-1)
				}
				}
			}
		},
	}
</script>

<style scoped>
	.header {
		width: 100%;
		height: 0.9rem;
		font-size: 0.36rem;
		line-height: 0.9rem;
		display: flex;
		justify-content: space-between;
		box-shadow: 0 0.01rem 0.02rem #aaa;
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		z-index: 9999;
	}

	.header-defualt {
		background-color: #f6f6f6;
	}

	.header-transparent {
		color: #FFFEFE;
	}

	.title {
		flex: 1;
		font-weight: 600;
		width: 65%;
		text-overflow: ellipsis;
		overflow: hidden;
		white-space: nowrap;
	}

	.save {
		flex: 0.2;
		color: #42B574;
		margin-right: .1rem;
	}

	.search {
		flex: 0.2;
		margin-right: .1rem;
	}
</style>
